package huawei;

import java.util.Scanner;

public class Question4 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String tag = scanner.nextLine();
        String streamStr = scanner.nextLine();

        Question4 question4 = new Question4();
        String val = question4.findVal(tag, streamStr);

        System.out.println(val);

//        Question4 question4 = new Question4();
//        System.out.println(question4.getVal('1', 1));
    }

    public String findVal(String target, String streamStr) {
        String[] strings = streamStr.trim().split(" ");
        int i = 0;
        StringBuilder sb = new StringBuilder();
        while (i < strings.length) {
            String tag = strings[i];
            int v = 0;
            String val = strings[i + 1];
            v += getVal(val.charAt(0), 1);
            v += getVal(val.charAt(1), 0);
            val = strings[i + 2];
            v += getVal(val.charAt(0), 3);
            v += getVal(val.charAt(1), 2);

            if (tag.equals(target)) {
                for (int j = i + 3; j < i + 3 + v; j++) {
                    sb.append(strings[j]);
                    if (j < i + 3 + v - 1) {
                        sb.append(" ");
                    }
                }
                break;
            } else {
                i += v + 3;
            }
        }
        return sb.toString();
    }

    public int getVal(Character v, int i) {
        int org = 0;
        if (v >= '0' && v <= '9') {
            org = v - '0';
        } else {
            org = v - 'A' + 10;
        }

        return org * (int) Math.pow(16, i);
    }


}
